package com.czy.owner.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.ParityModel;
import com.czy.owner.utils.DecimalUtil;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wangyang on 2017/5/18 0018.
 */

public class ParityListAdapter extends RecyclerArrayAdapter<ParityModel.GoodsPageBean.ListBean> {

    private Context context;

    public ParityListAdapter(Context context) {
        super(context);
        this.context = context;
    }


    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderViewHolder(parent);
    }

    class OrderViewHolder extends BaseViewHolder<ParityModel.GoodsPageBean.ListBean> {


        @BindView(R.id.img_logo)
        ImageView imgLogo;
        @BindView(R.id.tv_details)
        TextView tvDetails;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.tv_num)
        TextView tvNum;

        public OrderViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_parity_service);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(final ParityModel.GoodsPageBean.ListBean data) {
            super.setData(data);
            tvDetails.setText(data.getGoodsName());
            tvMoney.setText(DecimalUtil.formatNum(data.getPrice() + ""));
            tvNum.setText("已售" + data.getSoldCount() + data.getUnitName() + "|" + data.getCommentCount() + "评论");
            GlideUtils.loadImage(context, data.getGoodsLogo(), imgLogo, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);
        }
    }


}